'use strict';
app.controller('vipCtrl', ['$scope', 'utilService', 'vipService', '$modal', 'toaster', '$stateParams','$filter',function ($scope, utilService, vipService, $modal, toaster, $stateParams,$filter) {
    $scope.page = {};
    $scope.page.currentPage = 1;
    //分页
    $scope.replacePage = function () {
        $scope.currentPage = $scope.page.currentPage;
        $scope.pageChanged();
    };

    //查询身份设置列表
    $scope.query = function () {
        utilService.queryForPagingList($scope, {
            url: $scope.app.domain + 'vip'
        }).then(function (result) {
        });
    }
    $scope.query();
    //删除用户身份
    $scope.del = function (id) {
        // query data.
        openModal("确定要删除该用户身份吗？");
        function openModal(msg) {
            utilService.modal($modal, $scope, {
                title: "message",
                controller: "deleteCtrl",
                message: msg,
                data: id
            });
        }
    }
    $scope.identityObject = [
        //{name: '普通用户', value: '0'},
        {name: 'VIP用户', value: '1'},
        {name: '渠道合伙人', value: '2'}
    ]
    $scope.statusObject=[
        {name:'未支付',value:'0'},
        {name:'已支付',value:'1'},
        {name:'无需支付',value:'2'}
    ]
    $scope.vipHistoryListVO= {
        startTime: $filter('date')(new Date() - 30 * 24 * 60 * 60 * 1000, 'yyyy-MM-dd'),
        endTime: $filter('date')(new Date(), 'yyyy-MM-dd')
    }
    //身份交易记录查询
    $scope.queryVipHistory = function () {
        $scope.vipHistoryListVO.startTime=$filter('date')($scope.vipHistoryListVO.startTime,'yyyy-MM-dd');
        $scope.vipHistoryListVO.endTime=$filter('date')($scope.vipHistoryListVO.endTime,'yyyy-MM-dd');
        utilService.queryForPagingList($scope, {
            url: $scope.app.domain + 'vip/history',
            params: $scope.vipHistoryListVO
        }).then(function (rlt) {
            console.log(rlt);
        });
    }
    //切换类型
    $scope.changeType = function (type) {
        $scope.list = {};
        if (type == 0) {
            $scope.query();
        }
        if (type == 1) {
            $scope.vipHistoryListVO.nickName = "";
            $scope.vipHistoryListVO.identity = "";
            $scope.vipHistoryListVO.status = "";
            $scope.vipHistoryListVO.list = {};
            $scope.queryVipHistory();
        }
    }
}]);

app.controller('deleteCtrl', ['$scope', '$modalInstance', '$state', 'vipService', 'toaster', 'modalData',
    function ($scope, $modalInstance, $state, vipService, toaster, modalData) {
        $scope.modal = modalData;
        $scope.id = {
            id: modalData.data
        };
        $scope.isDelModal = true;

        $scope.ok = function () {
            if (!$scope.isDelModal) {
                return;
            }
            $scope.isDelModal = false;
            vipService.delete($scope).then(function (result) {
                switch (result.status) {
                    case 200:
                        $modalInstance.dismiss('success');
                        toaster.pop('success', "提示", "操作成功");
                        $scope.isDelModal = true;
                        $scope.query();
                        break;
                    default :
                        toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                        break;
                }
            });
        }
        //取消弹窗
        $scope.cancel = function () {
            $modalInstance.dismiss('cancel');
        };
    }
]);

app.controller('vipAddCtrl', ['$scope', 'vipService', 'toaster', '$state', function ($scope, vipService, toaster, $state) {

    $scope.vip = {
        identity: 0
    };

    $scope.addVip = function () {
        vipService.addVip($scope).then(function (result) {
            switch (result.status) {
                case 200:
                    toaster.pop('success', "提示", "操作成功");
                    $state.go('app.vip');
                    break;
                case 700:
                    toaster.pop('error', "操作失败", "该用户身份已设置，请重新选择.");
                    break;
                default :
                    toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                    break;
            }
        });
    }
}]);

app.controller('vipUpdateCtrl', ['$scope', 'vipService', 'toaster', '$state', '$stateParams', function ($scope, vipService, toaster, $state, $stateParams) {

    $scope.vipVO = {};
    $scope.vipId = $stateParams.id;
    $scope.findById = function () {
        vipService.findById($scope).then(function (result) {
            switch (result.status) {
                case 200:
                    $scope.vipVO = result.data;
                    break;
                default :
                    toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                    break
            }
        });
    };
    $scope.findById();

    $scope.updateVip = function () {
        vipService.updateVip($scope).then(function (result) {
            switch (result.status) {
                case 200:
                    toaster.pop('success', "提示", "操作成功");
                    $state.go('app.vip');
                    break;
                default :
                    toaster.pop('error', "操作失败", "发生未知错误！请联系管理员");
                    break
            }
        });
    }
}]);




























